package com.bdbit.ChargingStation.alipay;

import com.alipay.api.AlipayConfig;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 支付宝SDK配置类
 * 使用字符串密钥配置
 *
 * @author sheng
 */
public class Config {

    // 非公平锁
    private static final Lock lock = new ReentrantLock();
    /**
     *注意目前被注释的是支付宝沙箱环境的配置
     */
    // 应用私钥（请替换为您的实际私钥）
    private final String privateKey = "MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC9dtKFrYKHYJlHO5rGFXTznekD+9GD4flzVNJlac3lSN2dtZu0gSXAVJb+qZ6wOyG+RYRLCHjBxXBavWTEdKGIJIdeMz/HMVnx7YmnNdUL9NehTsvcX6Gr4ucvyn/wjUzWXTez9rTObLZ80n228t+BeRl7wFSV4OwE4QpyeUe6z6VwKR1nAPflOcshUfA7ktUwlvKB4OXRRDFFFbvpcVjhKagI33e5MMGYUr8XeGgY+YpsKxwjvdPIxmLpSusjt1O+EDgCxKF302EvNiE/SjjiqcjdZjzyFRcWDAjR+kjG2oCy5VedUaBG7RPb6V/YLUrAo3wNZ0nn3I6Ix4dBpYNTAgMBAAECggEAOIkQYNtZq9PjaSIcGSel8lwYgBvQdS4lJYkWDzT3P4fyuXDLuZ0gCrgzJmKu+59pfkF4LHumrQuhbzI8s3KqENn1muJoEaRkVpCvFro1jI/PGE9O/b97mrLmkZg3fSxs1TqTuJvRcBd4jN6yrLjkgNoGBKtrkh2/z+TnHSmbgd6XnIxaboHdOPLPc0YuB5CANY6lHCFeiw9b08wJn7YDJYs/G7kBzRmO/gJLxTLqGk9mu/nd9xNyMdxsauC1K2ZlzMNQL3sYZl1GVENiyBsWHjXahaOAlzH7PAvOJHQdcAdmhkZ2WxmOUVnsjrDrLptLriTJfz7A2BwLZdoCEeQ8oQKBgQD9l7tsdi/kng8TRx+kexPvTjZbrEBKhoyIzyQFl7dUHC7DgoheJwEnEGnFiv80C49BmWyzu5FLaL2VV+2RykZThJFo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Mps5fDGlKNFL82eZcooFsSe1X015a5ajAIKkatUvv1K87KavfyhDSM/cMCXZbQl1AweHnPPsbrjQeH1tg33ECgYEAjN3IBsvwM6lBB6aIW1uyLoDvvJY5m+94zr/ZFtHTRtyRjnkP8AEpf4M7fvA+KzNUccTG2Vy0B4PRlIhvTwQcLoBoooY/K19yxK1L/fCMymbAbGiMQQPS4PpJOlsP1ySDJiECtSYVXxwCp0mJJH2kFBk9VprZf+P5VIE+QfM3OJ4=";

    // 支付宝公钥（请替换为您的实际支付宝公钥）
    private final String alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkJ7qlhM2uLrbktxQB4asdQ/yaSCJk/kzHQE/NXHVbAcHYDGRCDOhWVbrUWcmhRegYfFJUmpS/GIa8trhOG4+QzmJvxvXqsb8ETkOpLUDjjHMK9HvdUp+G0Jomk8GsAY5yrE3Wi2X28sq4xukP0UA8U0X/ZvqmqYMFyVOwQ84ybK4nRVr3MMxf1b4Lu4MJvd7SSZhIx74FRjF3nB3VtlrGETIp+jsjHjJBAMHU7wV/ubuWeNOBU4+gjDKGkeay2pmWcMyEExVhbdNJojguM6Svb6h/pGaNVqw84RATcgsj/6A3NXrBSTpuKj40UK4uL+Z8vbze4AoE7I2rgXXJI6fVwIDAQAB";
//    private final String alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjx1jAkHgKdcTYFHssn6fJcY7NCYNCfkhk0SvlBnvBXtPMyeTsEj0Epyp+pZn7SeL6fNCd3KTNAqSWjExza1g5fOZOX8Es4OVpAOTJttbCQCsXSI8Mbh7mQf+6yHB80Uy7HzogkYwdeIRHqIqvAtWaSBi3swFLGNPudSj3sgcCLl/aqluAgTlXWwdF7fmH9YeOUS4d3d7Qy5TwIZkedrDokOYvoPVljxsoINn7bIFgF370aXe5Wp54oEkW9bkIQkVNnIcPPeG7r8WJ6AZLi/dvz1uMzr/Pnmb26Ho/QJQdBx7rbSMLosqmYG7+eHQpvXIQ56K3qiS+97l/tUfdGGIrwIDAQAB";

    // 应用公钥（请替换为您的实际应用公钥）
    private final String appPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvXbSha2Ch2CZRzuaxhV0853pA/vRg+H5c1TSZWnN5UjdnbWbtIElwFSW/qmesDshvkWESwh4wcVwWr1kxHShiCSHXjM/xzFZ8e2JpzXVC/TXoU7L3F+hq+LnL8p/8I1M1l03s/a0zmy2fNJ9tvLfgXkZe8BUleDsBOEKcnlHus+lcCkdZwD35TnLIVHwO5LVMJbygeDl0UQxRRW76XFY4SmoCN93uTDBmFK/F3hoGPmKbCscI73TyMZi6UrrI7dTvhA4AsShd9NhLzYhP0o44qnI3WY88hUXFgwI0fpIxtqAsuVXnVGgRu0T2+lf2C1KwKN8DWdJ59yOiMeHQaWDUwIDAQAB";
//    private final String appPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjXbXoEzJkDQ4qylm0vwvDuyiG5d6rYJTT7TNQco1oXJO+1pgjjNTiZrr8FTueQ+1To+Ci9G1H7f7iakvh5BeYba8VWlTcGtEugdkEsJTkxTSV5Nuh1Z5PtRHcBbfqhGB6evrj4EZC8V5X+yKB8OXdbHN75AmmzTgzd5t2Q8VzHangPjIfbMooE8YQBn+NR/ChmqgCfEaE+8UbR6HETbLqb9yFlKYOqTlZYOGOXBWGEjvugWgwVZXscATspcbEv32Y6V/xaJEj5b+Wo3RxRiibl4tvHjqmAKrx7GGVHGSY0snun6ItB1njmIpSTfd10SHa3YCUK9N1tBS10zvPxyjSwIDAQAB";

    private AlipayConfig alipayConfig;

    // 支付宝配置对象
    private static Config configInstance;

    private Config() {
    }

    /**
     * double-checking Locking
     */
    public static Config getInstance() {
        if (configInstance == null) {
            lock.lock();
            try {
                if (configInstance == null) {
                    configInstance = new Config();
                    configInstance.alipayConfig = new AlipayConfig();
                }
            } finally {
                lock.unlock();
            }
        }
        return configInstance;
    }

    public AlipayConfig getAlipayConfig() {
        // 基础配置
        alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
//        alipayConfig.setServerUrl("https://openapi-sandbox.dl.alipaydev.com/gateway.do");
        alipayConfig.setAppId("2021005179656596");
//        alipayConfig.setAppId("2021000148641198");
        alipayConfig.setPrivateKey(privateKey);
        alipayConfig.setAlipayPublicKey(alipayPublicKey);
        alipayConfig.setFormat("json");
        alipayConfig.setCharset("UTF-8");
        alipayConfig.setSignType("RSA2");
        
        return alipayConfig;
    }

    /**
     * 获取支付宝公钥
     * @return 支付宝公钥
     */
    public String getAlipayPublicKey() {
        return alipayPublicKey;
    }
    
    /**
     * 获取应用私钥
     * @return 应用私钥
     */
    public String getPrivateKey() {
        return privateKey;
    }
    
    /**
     * 获取应用公钥
     * @return 应用公钥
     */
    public String getAppPublicKey() {
        return appPublicKey;
    }
}
